package edu.ccut.saturn.component;

/**
 * 记录了验证错误信息，包括验证的数据、验证错误信息、产生验证错误的异常对象
 * 
 * @author 谷钰
 * 
 * @version 1.0 2008.9.03
 * 
 */
public class ValidateError {

	private String errorMessage;

	private Throwable exception;

	private Object validateValue;

	public ValidateError(String errorMessage, Throwable exception,
			Object validateValue) {

		this.errorMessage = errorMessage;
		this.exception = exception;
		this.validateValue = validateValue;
	}

	/**
	 * 获得验证错误的描述信息
	 * @return
	 */
	public String getErrorMessage() {
		return errorMessage;
	}

	/**
	 * 获得产生验证错误的异常信息
	 * @return
	 */
	public Throwable getException() {
		return exception;
	}

	/**
	 * 获得产生验证错误的验证对象
	 * @return
	 */
	public Object getValidateValue() {
		return validateValue;
	}

	/**
	 * 返回验证错误的字符串描述信息
	 */
	public String toString() {
		StringBuffer buffer = new StringBuffer("validate object : ").append(
				this.validateValue).append(" failed. Because : ").append(
				this.errorMessage).append(". ");

		if (this.exception != null) {
			buffer.append("Exception : ").append(this.exception.getMessage());
		}

		return buffer.toString();
	}
}
